import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;

/**
 * Created by Terry
 * Description:
 * User: GAOBO
 * Date: 2021-07-31
 * Time: 8:30
 */
//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}

//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}


@FunctionalInterface
interface MoreParameterReturn2 {
    double test(int a,double b);
}


class Test {

}


public class TestDemo {

    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");

      /* map.forEach(new BiConsumer<Integer, String>() {
            @Override
            public void accept(Integer integer, String s) {
                System.out.println("key: "+integer +" val " + s);
            }
        });*/
        map.forEach((key,val)-> System.out.println("key: "+key +" val " + val));
    }


    public static void main5(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("aello");
        list.add("bit");
        list.add("lambda");

        /*list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });*/
        //list.forEach((str)->{System.out.println(str);});
        list.forEach(str-> System.out.println(str));
        System.out.println("===========");

        /*list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });*/

        list.sort(((o1, o2) -> o1.compareTo(o2)));
        System.out.println("===========");
        list.forEach(str-> System.out.println(str));




    }



    public static void main4(String[] args) {
        int a = 99;

        NoParameterReturn noParameterReturn = ()->{
            //a = 100;
            System.out.println("捕获变量："+a);
            return 1;
        };
        int ret = noParameterReturn.test();
        System.out.println(ret);
    }

    public static void main3(String[] args) {
        int a = 10;
        new Test(){
            public void func() {
                //a = 99;
                System.out.println("捕获的变量："+a);
            }
        };
    }

    public static void main2(String[] args) {
        NoParameterReturn noParameterReturn = ()->{
            System.out.println("fafsaf");
            return 1;
        };
        int ret = noParameterReturn.test();
        System.out.println(ret);

        //当lambada表达式 只有一个语句的是  可以省略花括号
        NoParameterReturn noParameterReturn2 = ()->1;
        ret = noParameterReturn2.test();
        System.out.println(ret);

        System.out.println("==================");

//        OneParameterReturn oneParameterReturn = (a)->{return a;};
//        OneParameterReturn oneParameterReturn = (a)->a;
        OneParameterReturn oneParameterReturn = a->a;
        ret=oneParameterReturn.test(10);
        System.out.println(ret);
        System.out.println("==================");

//        MoreParameterReturn moreParameterReturn = (int a,int b)->{return a+b;};
//        MoreParameterReturn moreParameterReturn = (a,b)->{return a+b;};
        MoreParameterReturn moreParameterReturn = (a,b)->a+b;
        ret = moreParameterReturn.test(10,20);
        System.out.println(ret);
        System.out.println("==================");

        MoreParameterReturn2 moreParameterReturn2 = (int a,double b)->{return a+b;};

        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return 0;
            }
        });

        //看起来  牛逼了  实际上  代码的可读性变差了
        PriorityQueue<Integer> priorityQueue2 = new PriorityQueue<>((o1,o2)->{return o1-o2;});


    }

    public static void main1(String[] args) {

        NoParameterNoReturn noParameterNoReturn = ()->{
            System.out.println("haha");
        };

        noParameterNoReturn.test();

        System.out.println("===================");
        OneParameterNoReturn oneParameterNoReturn = (a)->{
            System.out.println(a);
        };
        oneParameterNoReturn.test(10);

        System.out.println("===================");

        MoreParameterNoReturn moreParameterNoReturn = (a,b) ->{
            System.out.println(a+b);
        };

        moreParameterNoReturn.test(10,20);
    }

}
